using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VFSZSTECH
    {
        public DataRow Convert2FSZSTECH(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryFSZSTECH(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["FSZSMANDANT"] = " ".PadRight(2 ); 
         dwReturn["FSZSFORM"] = " ".PadRight(10 ); 
         dwReturn["FSZSAENZL"] = " ".PadRight(0 ); 
         dwReturn["FSZSAENB"] = " ".PadRight(8 ); 
         dwReturn["FSZSAEND"] = " ".PadRight(0 ); 
         dwReturn["FSZSNEUB"] = " ".PadRight(8 ); 
         dwReturn["FSZSNEUD"] = " ".PadRight(0 ); 
         dwReturn["FSZSZSBEZ"] = " ".PadRight(50 ); 
         dwReturn["FSZSWART"] = " ".PadRight(3 ); 
         dwReturn["FSZSROHST"] = " ".PadRight(6 ); 
         dwReturn["FSZSZSVOR"] = " ".PadRight(3 ); 
         dwReturn["FSZSSTBRB"] = " ".PadRight(0 ); 
         dwReturn["FSZSBRTME"] = " ".PadRight(3 ); 
         dwReturn["FSZSBRTGRP"] = " ".PadRight(1 ); 
         dwReturn["FSZSBRTFKT"] = " ".PadRight(12 ); 
         dwReturn["FSZSLAHB"] = " ".PadRight(0 ); 
         dwReturn["FSZSLAHCM"] = " ".PadRight(0 ); 
         dwReturn["FSZSSTZFOS"] = " ".PadRight(3 ); 
         dwReturn["FSZSSTZFUS"] = " ".PadRight(3 ); 
         dwReturn["FSZSBLOCKL"] = " ".PadRight(0 ); 
         dwReturn["FSZSBLOCKM"] = " ".PadRight(3 ); 
         dwReturn["FSZSVERBR"] = " ".PadRight(0 ); 
         dwReturn["FSZSVBME"] = " ".PadRight(3 ); 
         dwReturn["FSZSVBGRP"] = " ".PadRight(1 ); 
         dwReturn["FSZSVBFKT"] = " ".PadRight(12 ); 
         dwReturn["FSZSMERKZ1"] = " ".PadRight(3 ); 
         dwReturn["FSZSMERKZ2"] = " ".PadRight(3 ); 
         dwReturn["FSZSMERKZ3"] = " ".PadRight(3 ); 
         dwReturn["FSZSFILLER"] = " ".PadRight(34 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapFSZSTECH(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveFSZSTECH(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryFSZSTECH(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapFSZSTECH(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertFSZSTECH(dwLocal, ITXDBVERSION);
            }
            UpdateFSZSTECH(dwLocal);
        }
        public void InsertFSZSTECH(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO FSZSTECH(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryFSZSTECH(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM FSZSTECH WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM FSZSTECH  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "FSZSTECH";
            Return = Result;
            return Return;
        }
        public void DeleteFSZSTECH(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM FSZSTECH   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateFSZSTECH(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE FSZSTECH SET "
                    +"FSZSMANDANT= :FSZSMANDANT,"
                    +"FSZSFORM= :FSZSFORM,"
                    +"FSZSAENZL= :FSZSAENZL,"
                    +"FSZSAENB= :FSZSAENB,"
                    +"FSZSAEND= :FSZSAEND,"
                    +"FSZSNEUB= :FSZSNEUB,"
                    +"FSZSNEUD= :FSZSNEUD,"
                    +"FSZSZSBEZ= :FSZSZSBEZ,"
                    +"FSZSWART= :FSZSWART,"
                    +"FSZSROHST= :FSZSROHST,"
                    +"FSZSZSVOR= :FSZSZSVOR,"
                    +"FSZSSTBRB= :FSZSSTBRB,"
                    +"FSZSBRTME= :FSZSBRTME,"
                    +"FSZSBRTGRP= :FSZSBRTGRP,"
                    +"FSZSBRTFKT= :FSZSBRTFKT,"
                    +"FSZSLAHB= :FSZSLAHB,"
                    +"FSZSLAHCM= :FSZSLAHCM,"
                    +"FSZSSTZFOS= :FSZSSTZFOS,"
                    +"FSZSSTZFUS= :FSZSSTZFUS,"
                    +"FSZSBLOCKL= :FSZSBLOCKL,"
                    +"FSZSBLOCKM= :FSZSBLOCKM,"
                    +"FSZSVERBR= :FSZSVERBR,"
                    +"FSZSVBME= :FSZSVBME,"
                    +"FSZSVBGRP= :FSZSVBGRP,"
                    +"FSZSVBFKT= :FSZSVBFKT,"
                    +"FSZSMERKZ1= :FSZSMERKZ1,"
                    +"FSZSMERKZ2= :FSZSMERKZ2,"
                    +"FSZSMERKZ3= :FSZSMERKZ3,"
                    +"FSZSFILLER= :FSZSFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("FSZSMANDANT", OracleType.NVarChar).Value = dwData["FSZSMANDANT"].ToString(); 
          or1.Parameters.Add("FSZSFORM", OracleType.NVarChar).Value = dwData["FSZSFORM"].ToString(); 
          or1.Parameters.Add("FSZSAENZL", OracleType.NVarChar).Value = dwData["FSZSAENZL"].ToString(); 
          or1.Parameters.Add("FSZSAENB", OracleType.NVarChar).Value = dwData["FSZSAENB"].ToString(); 
          or1.Parameters.Add("FSZSAEND", OracleType.NVarChar).Value = dwData["FSZSAEND"].ToString(); 
          or1.Parameters.Add("FSZSNEUB", OracleType.NVarChar).Value = dwData["FSZSNEUB"].ToString(); 
          or1.Parameters.Add("FSZSNEUD", OracleType.NVarChar).Value = dwData["FSZSNEUD"].ToString(); 
          or1.Parameters.Add("FSZSZSBEZ", OracleType.NVarChar).Value = dwData["FSZSZSBEZ"].ToString(); 
          or1.Parameters.Add("FSZSWART", OracleType.NVarChar).Value = dwData["FSZSWART"].ToString(); 
          or1.Parameters.Add("FSZSROHST", OracleType.NVarChar).Value = dwData["FSZSROHST"].ToString(); 
          or1.Parameters.Add("FSZSZSVOR", OracleType.NVarChar).Value = dwData["FSZSZSVOR"].ToString(); 
          or1.Parameters.Add("FSZSSTBRB", OracleType.NVarChar).Value = dwData["FSZSSTBRB"].ToString(); 
          or1.Parameters.Add("FSZSBRTME", OracleType.NVarChar).Value = dwData["FSZSBRTME"].ToString(); 
          or1.Parameters.Add("FSZSBRTGRP", OracleType.NVarChar).Value = dwData["FSZSBRTGRP"].ToString(); 
          or1.Parameters.Add("FSZSBRTFKT", OracleType.NVarChar).Value = dwData["FSZSBRTFKT"].ToString(); 
          or1.Parameters.Add("FSZSLAHB", OracleType.NVarChar).Value = dwData["FSZSLAHB"].ToString(); 
          or1.Parameters.Add("FSZSLAHCM", OracleType.NVarChar).Value = dwData["FSZSLAHCM"].ToString(); 
          or1.Parameters.Add("FSZSSTZFOS", OracleType.NVarChar).Value = dwData["FSZSSTZFOS"].ToString(); 
          or1.Parameters.Add("FSZSSTZFUS", OracleType.NVarChar).Value = dwData["FSZSSTZFUS"].ToString(); 
          or1.Parameters.Add("FSZSBLOCKL", OracleType.NVarChar).Value = dwData["FSZSBLOCKL"].ToString(); 
          or1.Parameters.Add("FSZSBLOCKM", OracleType.NVarChar).Value = dwData["FSZSBLOCKM"].ToString(); 
          or1.Parameters.Add("FSZSVERBR", OracleType.NVarChar).Value = dwData["FSZSVERBR"].ToString(); 
          or1.Parameters.Add("FSZSVBME", OracleType.NVarChar).Value = dwData["FSZSVBME"].ToString(); 
          or1.Parameters.Add("FSZSVBGRP", OracleType.NVarChar).Value = dwData["FSZSVBGRP"].ToString(); 
          or1.Parameters.Add("FSZSVBFKT", OracleType.NVarChar).Value = dwData["FSZSVBFKT"].ToString(); 
          or1.Parameters.Add("FSZSMERKZ1", OracleType.NVarChar).Value = dwData["FSZSMERKZ1"].ToString(); 
          or1.Parameters.Add("FSZSMERKZ2", OracleType.NVarChar).Value = dwData["FSZSMERKZ2"].ToString(); 
          or1.Parameters.Add("FSZSMERKZ3", OracleType.NVarChar).Value = dwData["FSZSMERKZ3"].ToString(); 
          or1.Parameters.Add("FSZSFILLER", OracleType.NVarChar).Value = dwData["FSZSFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
